<template>
  <div class="reservation-area" data-info="预约" v-loading="loading">
    <el-button class="next" @click="handleNext" type="primary">
      下一步{{ stepInfo }}
    </el-button>

    <div class="step-comps-area" data-info="具体的业务">
      <component
          :is="curCompName"
          @handlePatientInfoSure="handlePatientInfoSure"
      />
    </div>
    <!--底部操作-->
    <PatientNumberOperate :key="widget" @handleBack="handlePre"/>
  </div>
</template>

<script>

import CardType from '../comps/cardType';
import MedInsCode from '../comps/medInsCode';
import PatientInfo from '../comps/patientInfo';
import HospAreaInfo from '../comps/hospAreaInfo';
import PatientNumberDate from '../comps/patientNumberDate';
import OPType from '../comps/OPType';
import PatientDept from '../comps/patientDept';
import doctorSchedul from '../comps/doctorSchedul';
import PatientNumberTimeRang from '../comps/patientNumberTimeRang';
import PatientNumberInfo from '../comps/patientNumberInfo';
import RegisterInfo from '../comps/registerInfo';
import PatientNumberRezResult from '../comps/patientNumberRezResult';
import PatientNumberOperate from '../comps/patientNumberOperate'
import {v4 as uuid} from "uuid";
import lodash from "lodash";
import {buildParentApi} from "@/utils/designer/util";

let buildParent = buildParentApi();
export default {
  name: 'reservation',

  componentName: "reservation",

  components: {
    CardType,
    MedInsCode,
    PatientInfo,
    OPType,
    PatientDept,
    HospAreaInfo,
    PatientNumberDate,
    doctorSchedul,
    PatientNumberTimeRang,
    PatientNumberInfo,
    RegisterInfo,
    PatientNumberRezResult,
    PatientNumberOperate,
  },

  data() {
    return {
      widget: uuid(),
      curCompName: 'CardType',
      compsOptions: {
        1: 'CardType',
        2: 'MedInsCode',
        3: 'PatientInfo',
        4: 'HospAreaInfo',
        5: 'PatientNumberDate',
        6: 'OPType',
        7: 'PatientDept',
        8: 'doctorSchedul',
        9: 'PatientNumberTimeRang',
        10: 'RegisterInfo',
        11: 'PatientNumberRezResult',
      },
    }
  },

  computed: {
    shownOperate() {
      return this.steps !== 1;
    },

    // 步骤
    stepInfo() {
      return this.$store.getters['DRCbiz/getStepsInfo']
    },

    //获取Loading状态
    loading() {
      return this.$store.getters['layout/getLoading']
    },

    //选中的卡片信息
    cardTypeInfo() {
      return this.$store.getters['DRCbiz/getCardTypeInfo']
    },

    //选中的卡片信息
    OPTypeInfo() {
      return this.$store.getters['DRCbiz/getOPTypeInfo']
    },
  },

  mounted() {
  },

  methods: {
    async handleNext() {
      let stepInfo = parseInt(this.stepInfo)
      this.widget = uuid();
      if (stepInfo === 10) {
        await this.$store.dispatch('DRCbiz/setStepsInfo', 1)
      } else {
        await this.$store.dispatch('DRCbiz/setStepsInfo', ++stepInfo);
      }
    },

    // 返回上一层&首页
    async handlePre() {
      this.widget = uuid();
      let stepInfo = parseInt(this.stepInfo);
      if (stepInfo === 1) {
        await this.$router.push({
          path: `/apptsReg/2`
        });
      } else {
        await this.$store.dispatch('DRCbiz/setStepsInfo', --stepInfo);
      }
      switch (parseInt(this.stepInfo)) {
        case 2:
          let cardTypeInfo = (this.cardTypeInfo);
          Reflect.set(cardTypeInfo, 'cardNo', null);
          await this.$store.dispatch('DRCbiz/setCardTypeInfo', cardTypeInfo);
          buildParent.executeParentMethod('openScan');
          break
      }
    },

    // 点击患者切换到下一个视图
    handlePatientInfoSure() {
      console.log('患者确定-->')
      let stepInfo = parseInt(this.stepInfo);
      this.$store.dispatch('DRCbiz/setStepsInfo', ++stepInfo)
    },

  },

  watch: {
    // 步距
    stepInfo: {
      handler: function (val) {
        const self = this;
        self.widget = uuid();
        let cardTypeInfo = (this.cardTypeInfo);
        if (val === 2) {
          if (parseInt(cardTypeInfo?.id) === 29) {
            buildParent.executeParentMethod('MICode');
          } else {
            buildParent.executeParentMethod('openScan');
          }
        } else {
          buildParent.executeParentMethod('closeScan');
        }
        self.$store.dispatch('DRCbiz/setCTDTimeInfo', 90000);
        // 依据所选科室门诊类型不同--视图会有差异
        self.curCompName = Reflect.get(self.compsOptions, val);
      },
      deep: true,
      immediate: true,
    },
  }
}

</script>

<style scoped lang="scss">
@import "./assets/style";
</style>